home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.07 Jul 91 / MacLock 1.0 / CMacLockApp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-27  |  4.4 KB  |  189 lines  |  [TEXT/KAHL]

  1. /*****
  2.  *
  3.  * FILE:         CMacLockApp.c
  4.  * Programmer:     Mark Bykerk Kauffman
  5.  * Date:        1/91
  6.  * Purpose:        
  7.  *        Application methods for CMacLockApp.
  8.  *
  9.  * PARENTCLASS = CStarterApp    
  10.  *
  11.  *****/
  12.  
  13. #include "Commands.h"        /* So cmdOpen and cmdAbout work inDoCommand.*/
  14. #include "MacLockCmds.h"    /* This applications commands for DoCommand */
  15. #include "CMacLockApp.h"    
  16. #include "CMacLockDoc.h"    
  17. #include <CFWDesktop.h>        /*  Floating Window Desktop.                */
  18. #include "CBartender.h"        
  19. #include "CAboutMacLock.h"
  20. #include "CPassword.h"
  21.  
  22. /* Global Variables for objects of this class.    */
  23. extern    CBartender *gBartender;
  24. extern CDesktop        *gDesktop;            /* The visible Desktop            */
  25. extern CBureaucrat    *gGopher;            /* First in line to get commands*/
  26. CPassword        *gThePassword;
  27.  
  28. /* METHOD IMPLEMENTATIONS */
  29.  
  30. /*****
  31.  * IMacLockApp
  32.  *
  33.  *    Initialize the application.  Create an object, gThePassword, which
  34.  *  is global to the application and initialize it.  Call the parent class
  35.  *  initialization method.
  36.  *
  37.  *****/
  38.  
  39. void CMacLockApp::IMacLockApp(void)
  40. {
  41.     gThePassword = new(CPassword);
  42.     gThePassword->IPassword();
  43.     CStarterApp::IStarterApp();
  44. }
  45.  
  46. /*****
  47.  * StartUpAction
  48.  *
  49.  * Start the application by asking for money.
  50.  *        
  51.  *****/
  52.  
  53. void    CMacLockApp::StartUpAction(
  54.     short    numPreloads)
  55. {
  56.     gGopher->DoCommand(cmdAbout);
  57.     inherited::StartUpAction(numPreloads);
  58. }
  59.  
  60.  
  61. /*****
  62.  * MakeDesktop
  63.  *
  64.  *        Use the Desktop subclass which supports floating windows.
  65.  *        This was absolutly necessary to make the AboutMacLock work
  66.  *        properly.  Without floating windows, the lock window was deselected
  67.  *        every time the AboutMacLock was called up.
  68.  *        
  69.  *****/
  70.  
  71. void    CMacLockApp::MakeDesktop()
  72. {
  73.     gDesktop = new(CFWDesktop);
  74.     ((CFWDesktop*)gDesktop)->IFWDesktop(this);
  75. }
  76.     
  77. /*****
  78. * UpdateMenus 
  79. *  Menu management.
  80. *
  81. *****/
  82.  
  83. void    CMacLockApp::UpdateMenus()
  84. {
  85.     inherited::UpdateMenus();
  86.     gBartender->EnableCmd(cmdPassword);
  87. }
  88.  
  89.  
  90. /*****
  91.  * DoCommand
  92.  *
  93.  *    Commands 1-1023 are reserved.  cmdPassword is defined in MacLockCmds.h,
  94.  *  cmdOpen and cmdAbout are defined in Commands.h.  The inherited method 
  95.  *  should always be called as the default of your switch statement so that
  96.  *  all standard commands that you don't handle will be taken care of.
  97.  *
  98.  *****/
  99. void CMacLockApp::DoCommand(long theCommand)
  100.  
  101. {
  102.     int        numberofitems;
  103.     CAboutMacLock    *theAboutMacLock;
  104.     CWindow        *oldWindow;
  105.     
  106.     switch (theCommand) {
  107.     
  108.         /* These are the commands that MacLock responds to. */
  109.         
  110.          case cmdOpen:
  111.                  /* Override the inherited response to cmdOpen.  Check
  112.                     how many directors the application has by sending a
  113.                     GetNumItems message to itsDirectors.  If there are
  114.                     two, then the application already has a MacLock window
  115.                     on the screen and we don't want to display another.
  116.                     Remove the if statement and you will get another
  117.                     MacLock window every time you do an Open from the menu
  118.                     or press command-O.*/    
  119.                  numberofitems = itsDirectors->GetNumItems();
  120.                  if (numberofitems < 2)                       
  121.                      CreateDocument();  
  122.                  break;
  123.                                         
  124.         case cmdPassword:
  125.                 gThePassword->ChangePassword();
  126.                 break;
  127.                         
  128.         case cmdAbout:
  129.             theAboutMacLock = new(CAboutMacLock);
  130.             theAboutMacLock->IAboutMacLock(this);
  131.             theAboutMacLock->Dispose();
  132.              FlushEvents(mDownMask+mUpMask+keyDownMask+keyUpMask
  133.                             +autoKeyMask, 0);
  134.             break;
  135.  
  136.         /* Call the inherited DoCommand here.*/
  137.         default:    inherited::DoCommand(theCommand);
  138.                     break;
  139.     }
  140. }
  141.  
  142. /*****
  143.  * CreateDocument
  144.  *
  145.  * Create the unique MacLock Document.  Send it a newFile message so that
  146.  * it opens a new MacLock window.
  147.  *
  148.  *****/
  149.  
  150. void CMacLockApp::CreateDocument()
  151.  
  152. {
  153.     CMacLockDoc    *theDocument;
  154.     
  155.     theDocument = new(CMacLockDoc);        
  156.     theDocument->IMacLockDoc(this, TRUE);
  157.     theDocument->NewFile();
  158. }
  159.  
  160. /*****
  161.  * OpenDocument
  162.  *
  163.  *    The user chose Open… from the File menu.  Create a new Maclock document
  164.  *  (if one hasn't already been created).
  165.  *
  166.  *****/
  167.  
  168. void CMacLockApp::OpenDocument(SFReply *macSFReply)
  169.  
  170. {
  171.     CMacLockDoc    *theDocument;
  172.     
  173.     theDocument = new(CMacLockDoc);
  174.         
  175.          /*    Send your document an initialization
  176.             message. The first argument is the
  177.             supervisor (the application). The second
  178.              argument is TRUE if the document is printable.*/
  179.     
  180.     theDocument->IMacLockDoc(this, TRUE);
  181.  
  182.         /*    Send the document an OpenFile() message.
  183.             The document will open a window, open
  184.             the file specified in the macSFReply record,
  185.             and display it in its window.*/
  186.             
  187.     theDocument->OpenFile(macSFReply);
  188.  }